import 'dart:convert';

import 'package:flutter_des/flutter_des.dart';

import '../public.dart';

// ignore: slash_for_doc_comments
/**
{
 "title":"第1章黄色水晶球",
 "detail":"暂无介绍",
 "chapter_id":"14474713"
 }
 **/
class ChapterService {
  static Future<List<Chapter>> findAll(
      {String bookId,
      String reptileType,
      String bookName,
      String author,
      String bookUrl}) async {
    String param = await FlutterDes.encryptToHex(
        "&bookName=$bookName&"
        "bookUrl=$bookUrl&"
        "reptileType=$reptileType&"
        "author=$author",
        AppConfig.cryptKey,
        iv: AppConfig.cryptIv);
    String url = AppConfig.BASE_UEL + Api.findAllChapter + param.toString();
    List<Chapter> chapters = [];
    BaseResp res = await HttpManager().request(url);
    Map<String, dynamic> jsonObject = jsonDecode(res.data);
    List<dynamic> _list = jsonObject['catalog'];
    chapters = Chapter.listFromJson(_list);
    return chapters;
  }
}
